#include <stdio.h>
#include <stdlib.h>

typedef struct Node {                       
    int data;
    struct Node *next;
} Node;

Node *getWinner(Node *head, int m) {
    Node *it = head;
    while (head->next != NULL) {
        for (int i = 0; i < m - 2; i++) {
            if (it->next == NULL)
                it = head;
            else
                it = it->next;
        }
        if (it->next == NULL) {
            head = head->next;
            it = head;
        } else {
            it->next = it->next->next;
            if (it->next == NULL)
                it = head;
            else
                it = it->next;
        }
        // printf("%d\n", it->data);
        // for (Node *i = head; i; i = i->next) printf("%s%d->", ((i == it) ? "__" : ""), i->data);
        // printf("\n");
    }
    return head;
}

Node *createList(int n) {
    Node *head = NULL, *tail = NULL;
    for (int i = 1; i <= n; i++) {
        Node *newNode = (Node *)malloc(sizeof(Node));
        newNode->data = i;
        if (head == NULL) {
            head = newNode;
        } else {
            tail->next = newNode;
        }
        tail = newNode;
    }
    tail->next = NULL;
    return head;
}

int main() {
    int n, m;
    scanf("%d %d", &n, &m);
    Node *head = createList(n);
    Node *winner = getWinner(head, m);
    if (winner)
        printf("%d", winner->data);
    else
        printf("NULL");
    return 0;
}